/*
 * Project Name: xdtech-core
 * File Name: ModelTableServiceImpl.java
 * Copyright: Copyright(C) 1985-2015 ZKTeco Inc. All rights reserved.
 */
package com.xdtech.coder.service.impl;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.xdtech.coder.dao.ModelTableDao;
import com.xdtech.coder.model.ModelTable;
import com.xdtech.coder.service.ModelTableService;
import com.xdtech.coder.vo.ModelTableItem;
import com.xdtech.core.model.BaseItem;
import com.xdtech.core.orm.utils.BeanUtils;
import com.xdtech.web.model.Pagination;

/**
 * @author max.zheng
 * @version TODO 添加版本
 * @see 相关类或方法，不需要请删除此行
 * @since 2015-2-4 下午2:07:11
 */
@Service
public class ModelTableServiceImpl implements ModelTableService
{
	@Autowired
	private ModelTableDao modelTableDao;
	/* (非 Javadoc)
	 * save
	 * <p>对override方法的补充说明，若不需要则删除此行</p>
	 * 
	 * @param entity
	 * @see com.xdtech.common.service.IBaseService#save(com.xdtech.core.model.BaseModel)
	 */
	
	public void save(ModelTable entity)
	{
		modelTableDao.save(entity);
	}

	/* (非 Javadoc)
	 * delete
	 * <p>对override方法的补充说明，若不需要则删除此行</p>
	 * 
	 * @param entity
	 * @see com.xdtech.common.service.IBaseService#delete(com.xdtech.core.model.BaseModel)
	 */
	
	public void delete(ModelTable entity)
	{
		modelTableDao.delete(entity);
	}

	/* (非 Javadoc)
	 * delete
	 * <p>对override方法的补充说明，若不需要则删除此行</p>
	 * 
	 * @param id
	 * @see com.xdtech.common.service.IBaseService#delete(java.lang.Long)
	 */
	
	public void delete(Long id)
	{
		modelTableDao.delete(id);
	}

	/* (非 Javadoc)
	 * get
	 * <p>对override方法的补充说明，若不需要则删除此行</p>
	 * 
	 * @param id
	 * @return
	 * @see com.xdtech.common.service.IBaseService#get(java.lang.Long)
	 */
	public ModelTable get(Long id)
	{
		return modelTableDao.get(id);
	}

	/* (非 Javadoc)
	 * getAll
	 * <p>对override方法的补充说明，若不需要则删除此行</p>
	 * 
	 * @return
	 * @see com.xdtech.common.service.IBaseService#getAll()
	 */
	public List<ModelTable> getAll()
	{
		return modelTableDao.getAll();
	}

	/* (非 Javadoc)
	 * loadPageAndCondition
	 * <p>对override方法的补充说明，若不需要则删除此行</p>
	 * 
	 * @param pg
	 * @param values
	 * @return
	 * @see com.xdtech.common.service.IBaseService#loadPageAndCondition(com.xdtech.web.model.Pagination, java.util.Map)
	 */
	
	public Map<String, Object> loadPageAndCondition(Pagination pg, Map<String, String> values)
	{
		return null;
	}

	/* (非 Javadoc)
	 * getAllItems
	 * <p>对override方法的补充说明，若不需要则删除此行</p>
	 * 
	 * @return
	 * @see com.xdtech.coder.service.ModelTableService#getAllItems()
	 */
	
	public List<ModelTableItem> getAllItems()
	{
		List<ModelTable> modelTables = getAll();
		List<ModelTableItem> items = new ArrayList<ModelTableItem>();
		ModelTableItem item = null;
		for (ModelTable modelTable : modelTables)
		{
			item = new ModelTableItem();
			BeanUtils.copyProperties(item, modelTable);
			items.add(item);
		}
		return items;
	}

	/* (非 Javadoc)
	 * saveAll
	 * <p>对override方法的补充说明，若不需要则删除此行</p>
	 * 
	 * @param entities
	 * @see com.xdtech.common.service.IBaseService#saveAll(java.util.List)
	 */
	public void saveAll(List<ModelTable> entities)
	{
		modelTableDao.saveAll(entities);
	}

	/* (非 Javadoc)
	 * deleteModelTables
	 * <p>对override方法的补充说明，若不需要则删除此行</p>
	 * 
	 * @param idList
	 * @see com.xdtech.coder.service.ModelTableService#deleteModelTables(java.util.List)
	 */
	public void deleteModelTables(List<Long> idList)
	{
		for (Long id : idList)
		{
			modelTableDao.excuteSql("delete from coder_model_field where table_id=?", id);
			modelTableDao.delete(id);
		}
		
		
	}

	/**
	 * @description
	 * @author max.zheng
	 * @create 2015-4-18下午12:14:58
	 * @modified by
	 * @param pg
	 * @param baseItem
	 * @param queryName
	 * @return
	 */
	@Override
	public Map<String, Object> loadPageDataByConditions(Pagination pg,
			BaseItem baseItem, String queryName) {
		// TODO Auto-generated method stub
		return null;
	}

}
